import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:convert';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:html_character_entities/html_character_entities.dart';
class Description extends StatefulWidget {

  final Map<String,dynamic> description;
  Description({this.key,this.description});
  final key;
  _DescriptionState createState() => _DescriptionState();
}

class _DescriptionState extends State<Description> with AutomaticKeepAliveClientMixin{
  bool get wantKeepAlive => true;
  WebViewController _controller;
  @override
  void initState() {

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    String description =widget.description['description'];
    description ='data:text/html;base64,'+base64Encode(const Utf8Encoder().convert(HtmlCharacterEntities.decode(description)));
    double _height = 100;

    return Container(
//      key:widget.key,
      height:1500,
       child:Column(
         mainAxisSize: MainAxisSize.max,
         crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          SizedBox(height: 20.w,),
          Container(
            width:750.w,
            height:50,
            margin:EdgeInsets.only(bottom: 20.h),
            decoration: BoxDecoration(
              color:Colors.white
            ),
            alignment: Alignment.center,
            child: Text('产品介绍',style: TextStyle(
                fontSize: 30.sp
            ),)
          ),
Container(
  decoration: BoxDecoration(
    color: Colors.white
  ),
  child:           WebView(
    initialUrl: 'data:text/html;base64,$description',
    javascriptMode: JavascriptMode.unrestricted,
    onWebViewCreated: (controller) {
      _controller = controller;
//              controller.loadUrl(Uri.dataFromString(htmlStr,
//                  mimeType: 'text/html', encoding: Encoding.getByName('utf-8'))
//                  .toString());
    },
    onPageFinished: (url){
      print('url1:$url');
      //调用JS得到实际高度
      _controller.evaluateJavascript("document.documentElement.clientHeight;").then((result){
        print("result:123");
        print(result);
        setState(() {
          _height = double.parse(result);
          print("高度：$_height");
        });
      }
      );
    },
  )
  ,
)        ],
      ),
    );
  }
}